package com.test.rabbitmq;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author : caili
 * @date : 11:21 2023/1/17
 */
@Component
@Slf4j
public class DelayReceiver {
    @RabbitListener(queues = "delay.queue", ackMode = "MANUAL")
    public void process(String pMessage, Message message, Channel channel) throws IOException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("["+sdf.format(new Date())+"]死信队列接收生产中消息:{}", pMessage);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //设置手动应答 方便演示不做业务逻辑和异常处理了
        channel.basicAck(deliveryTag, false);
    }
}
